from django.contrib.sitemaps import Sitemap
from models import Announcement, Event
from datetime import datetime

class NewsSitemap(Sitemap):
    protocol = 'https'
    changefreq = "daily"
    priority = 0.7

    def items(self):
	return ['News']

    def lastmod(self, obj):
	LatestAnnouncement = datetime(2011,1,1)
	LatestEvent = datetime(2011,1,1)
	if Announcement.objects.all():
		LatestAnnouncement = Announcement.objects.order_by('-date')[0].date
	if Event.objects.all():
		LatestEvent = Event.objects.order_by('-date')[0].date
	return max(LatestAnnouncement, LatestEvent)

    def location(self, obj):
	return course_reverse('news.views.index')
